package java;

import indi.cloud.common.elasticsearch.EsDataService;
import indi.cloud.common.elasticsearch.core.EsDocBeanEntity;
import indi.cloud.common.elasticsearch.core.EsResult;
import indi.cloud.common.model.esresult.EsEnterpriseListEntity;
import indi.cloud.common.model.esdoc.EsEnterpriseListDoc;
import org.junit.jupiter.api.Test;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yangyifan
 * @version 1.0
 * @date 2024/1/29 15:28
 * @Description
 */
public class esJunit {

    @Resource
    private EsDataService esDataService;

    @Test
    public void search2() {
        EsEnterpriseListDoc request = new EsEnterpriseListDoc();
        request.setPage(1);
        request.setSize(3);

        EsResult<List<EsEnterpriseListEntity>> search = esDataService.search(EsEnterpriseListEntity.class, request);

        System.out.println(search);
    }

//    @Test
//    public void sqlSearch() {
//        String sql = null;
//        sql = "SELECT * FROM ems limit 10";
//
//        List<EsDocBeanEntity> esDocBeanEntityList = esDataService.sqlSearch(EsDocBeanEntity.class, sql);
//        System.out.println("gson.toJson(esDocBeanList) = " + gson.toJson(esDocBeanEntityList));
//    }

//    @Test
//    public void bbossQueryTest() {
//        //TODO 需要yml中配置bboss相关属性才可使用
//        ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
//        SQLResult<EsDocBeanEntity> sqlResult = clientUtil.fetchQuery(EsDocBeanEntity.class, "{\"query\": \"SELECT * FROM ems\"}");
//        List<EsDocBeanEntity> datas = sqlResult.getDatas();
//        System.out.println("gson.toJson(datas) = " + gson.toJson(datas));
//    }


//    private EsDocBeanEntity createOne() {
//        EsDocBeanEntity b1 = new EsDocBeanEntity("XX" + RandomUtils.nextInt(1, 10000), "XX" + RandomUtils.nextInt(1, 10000), "xxx" + RandomUtils.nextInt(1, 10000), RandomUtils.nextInt(1, 10000));
//        EsDocBeanEntity save = esDataService.save(b1);
//        try {
//            //延迟一下，等待es执行
//            TimeUnit.SECONDS.sleep(1);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        return save;
//    }

    private boolean deleteOne(EsDocBeanEntity esDocBeanEntity) {
        return esDataService.delete(EsDocBeanEntity.class, esDocBeanEntity.getId());
    }

}
